home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 5
/
Gold Medal Software - Volume 5 (Gold Medal) (1995).iso
/
windows
/
win31
/
cenviw.arj
/
IDLETIME.CMM
< prev
next >
Wrap
Text File
|
1994-03-08
|
5KB
|
157 lines
/**********************************************************************
*** IdleTime - CEnvi program to start a maximized clock after the ***
*** ver.1 mouse and keyboard buttons have been idle, and then ***
*** terminate the clock when the buttons are active ***
*** again. This code checks for keyboard or mouse ***
*** activity by periodically checking the global ***
*** keyboard table and checking the mouse position ***
**********************************************************************/
#define DELAY_WHILE_WAITING 5
// Delay, in seconds, between each check for activity, while waiting
// for inactivity
#define INACTIVE_PERIOD 3
// How many minutes of keyboard inactivity will start the program
#define DELAY_WHILE_EXECUTING 500
// Delay, in milliseconds (1000 = 1 second), while waiting for
// keyboard or mouse activity to start again
#include <WinTools.lib>
#include <MenuCtrl.lib>
#include <KeyPush.lib>
main() // this is where the program begins. This will loop forever
{
// Uncomment ("remove "//") from following line to hide CEnvi icon
// HideThisCEnviProgram(); // make CEnvi icon invisible
while(TRUE) {
WaitForInactivity(); // wait for period of inactivity
window = StartProgram();// start program, and get handle
if ( window ) {
WaitForActivity(); // wait for a keyboard or mouse press
EndProgram(window);
}
}
}
ShowDigital, ShowSeconds, ShowTitle;
ShowMaximized, ShowMinimized;
IStartedClock;
StartProgram() // Start the clock program, maximize it and return
{ // a handle, or return 0 if cannot start it
if ( IStartedClock = !(window = GetWindowHandle("clock")) ) {
spawn(P_NOWAIT,"CLOCK.EXE");
if ( !(window = GetWindowHandle("clock")) )
return(0);
}
// remember state of clock for later restoration
ShowMaximized = IsMaximized(window);
ShowMinimized = IsMinimized(window);
if ( !ShowMaximized )
ShowWindow(window,SW_SHOWMAXIMIZED);
// remember menu selections to be restored
if ( !(ShowTitle = (Menu = GetMenu(window))) ) {
// there is no menu; escape key toggles menu on clock
KeyPushFocusID(window);
KeyStroke(VK_ESCAPE);
Menu = GetMenu(window);
}
ShowDigital = MF_CHECKED & GetMenuState(Menu,FindMenuString(Menu,"Digital"),MF_BYCOMMAND);
ShowSeconds = MF_CHECKED & GetMenuState(Menu,FindMenuString(Menu,"Seconds"),MF_BYCOMMAND);
// my favorite clock settings
if ( ShowDigital )
MenuCommand(window,"Analog",True);
if ( !ShowSeconds )
MenuCommand(window,"Seconds",True);
MenuCommand(window,"No Title",True); // hide the title bar
return(window);
}
EndProgram(handle) // reset window settings and close window
{
if ( IsWindow(handle) ) {
// if not title now then make one so we can use the menu
if ( !GetMenu(handle) ) {
KeyPushFocusID(handle);
KeyStroke(VK_ESCAPE);
}
if ( ShowDigital )
MenuCommand(handle,"Digital",True);
if ( !ShowSeconds )
MenuCommand(handle,"Seconds",True);
if ( !ShowMaximized )
ShowWindow(handle,ShowMinimized ? SW_SHOWMINIMIZED : SW_RESTORE);
if ( !ShowTitle )
MenuCommand(handle,"No Title",True);
if ( IStartedClock )
SystemMenuCommand(handle,"Close");
}
}
WaitForInactivity() // check every once in a while, and return after a
{ // long period of inactivity
// check at every interval and set keyboard if it is not already set
PrevTable = GetGlobalKeyboardTable();
PrevPos = CursorPosition();
EndTime = time() + (INACTIVE_PERIOD * 60);
// stay in this block until period of inactivity has occurred
do {
suspend(DELAY_WHILE_WAITING * 1000); // wait a while
CurrentTable = GetGlobalKeyboardTable();
CurrentPos = CursorPosition();
if ( memcmp(CurrentTable,PrevTable,256) || CurrentPos != PrevPos ) {
// table has changed; reset EndTime and remember table
EndTime = time() + (INACTIVE_PERIOD * 60);
PrevTable = CurrentTable;
PrevPos = CurrentPos;
}
} while ( time() < EndTime );
}
WaitForActivity() // check every once in a while, and return after a
{ // change in the keyboard or mouse
PreviousTable = GetGlobalKeyboardTable();
PrevPos = CursorPosition();
while( !memcmp(PreviousTable,GetGlobalKeyboardTable(),256)
&& PrevPos == CursorPosition() ) {
suspend(DELAY_WHILE_EXECUTING);
}
}
GetGlobalKeyboardTable() // return 256 byte buffer for current
{ // keyboard state
keyBuf[255] = '\0'; // initialize a 256-byte array
DynamicLink("USER","GETKEYBOARDSTATE",SWORD16,PASCAL,keyBuf);
return(keyBuf);
}
HideThisCEnviProgram() // hide the CEnvi window icon
{
ShowWindow(ScreenHandle(),SW_HIDE);
}
CursorPosition() // return current cursor position in screen coordinates
{ // structure elements returned are .col and .row
BLObSize(point,4);
DynamicLink("USER","GETCURSORPOS",SWORD16,PASCAL,point);
position.col = BLObGet(point,0,SWORD16);
position.row = BLObGet(point,2,SWORD16);
return(position);
}